package concurrent.thread_create;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class MyCallable implements Callable<String> {
    @Override
    public String call() throws Exception {
        System.out.println("3......");
        return "zhuZi";
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Callable callable = new MyCallable();
        //FutureTask 实际上也是继承了run方法,只是他在执行run方法的时候，调用了call方法，从而达到获得返回值的目的
        //FutureTask内部返回的其实是outcome
        FutureTask<String> futureTask = new FutureTask<>(callable);
        new Thread(futureTask).start();
        System.out.println(futureTask.get());
    }
}
